//
//  XZFunction.m
//  生活小助手
//
//  Created by lixiangzhou on 14-8-7.
//  Copyright (c) 2014年 lxz. All rights reserved.
//

#import "XZFunctionView.h"

#define kTitleHeight 20
#define kIconHeight 80

@interface XZFunctionView ()
@end

@implementation XZFunctionView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        self.height = kFunctionHeight;
        self.width = kFunctionWidth;
    }
    return self;
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat x = 0;
    CGFloat y = kIconHeight;
    CGFloat width = contentRect.size.width;
    CGFloat height = kTitleHeight;
    return CGRectMake(x, y, width, height);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat width = contentRect.size.width;
    CGFloat height = kIconHeight;
    return CGRectMake(x, y, width, height);
}

+ (instancetype)functionViewWithIcon:(NSString *)icon title:(NSString *)title type:(XZFunctionViewType)type
{
    XZFunctionView *functionView = [[XZFunctionView alloc] init];
    functionView.tag = type;
    [functionView addTarget:functionView action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    functionView.imageView.image = [UIImage imageNamed:icon];
    functionView.imageView.contentMode = UIViewContentModeCenter;
    [functionView setTitle:title forState:UIControlStateNormal];
    functionView.titleLabel.font = [UIFont systemFontOfSize:15];
    functionView.titleLabel.textAlignment = NSTextAlignmentCenter;
    [functionView setNeedsDisplay];
    return functionView;
}

- (void)btnClick:(XZFunctionView *)sender
{
    if ([self.delegate respondsToSelector:@selector(functionView:didClickType:)]) {
        [self.delegate functionView:self didClickType:sender.tag];
    }
}


@end
